Skip to content

Conversation

@kpavlov
Copy link
Contributor

@kpavlov kpavlov commented Nov 5, 2025

Refactor MCP Protocol and related classes for improved exception handling and annotations.

  • Add null as the default value for optional fields in MCP types.
  • Rename McpError to McpException for clarity and better usability. Move to a separate file. Use it in some places instead of IllegalStateException. Create McpException from JSONRPCError with JSONRPCError.toMcpException()
  • Move AbstractTransport to a separate file.
  • Improve ServerPromptsTest cases with new scenarios and assertions.
  • Gradle: Downgrade kotest assertions library to support JDK 8.
  • Reformat KDocs and fix Detekt issues
  • Add additional @Suppress annotations to improve readability and control warnings.

Motivation and Context

Improve ServerPromptsTest;
Provide default values to simplify API usage.
To make use of MCP-specific errors instead of generic IllegalStateException
Cleanup code to make issues visible in Detekt.

How Has This Been Tested?

Unit/Integraiton tests, regression tests

Breaking Changes

getPrompt throws new McpException (ex McpError) instead of IllegalStateException.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tests added

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@kpavlov kpavlov added documentation Improvements or additions to documentation tests refactoring Making things better labels Nov 5, 2025
…ndling and annotations.

- Encapsulate exception handling with `toMcpException`.
- Move `AbstractTransport` to a separate file.
- Add `null` as the default value for optional fields in MCP types.
- Rename `McpError` to `McpException` for clarity and better usability. Move to a separate file. Use it in some places instead of IllegalStateException
- Gradle: Downgrade `kotest` assertions library to support JDK 8.
- Improve `ServerPromptsTest` cases with new scenarios and assertions.
- Reformat KDocs and fix Detekt issues
- Add additional `@Suppress` annotations to improve readability and control warnings.
@kpavlov kpavlov force-pushed the kpavlov/refactor-errors-and-tests branch from 807e4a5 to 953acce Compare November 5, 2025 18:54
* corresponding [_onClose], [_onError] and [_onMessage] properties to use for an implementation.
*/
@Suppress("PropertyName")
public abstract class AbstractTransport : Transport {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to separate file

Comment on lines +56 to +63
client.getPrompt(GetPromptRequest("test-prompt-with-custom-handler")) shouldBe expectedPromptResult

client.listPrompts() shouldNotBeNull {
prompts shouldContainExactly listOf(testPrompt)
nextCursor shouldBe null
_meta shouldBe EmptyJsonObject
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We SHOULD verify that the prompt was actually added

Comment on lines +126 to +128
client.listPrompts() shouldNotBeNull {
prompts.shouldBeEmpty()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually verify, that prompts were removed

@Test
fun `removePrompt should throw when prompts capability is not supported`() = runTest {
@Nested
inner class NoPromptsCapabilitiesTests {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group negative scenarios

verify {
rule {
minBound(65)
minBound(75)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rise the bar

@kpavlov kpavlov marked this pull request as ready for review November 5, 2025 19:05
Copy link
Contributor

@tiginamaria tiginamaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice! Thank you

@kpavlov kpavlov marked this pull request as draft November 6, 2025 10:22
@kpavlov
Copy link
Contributor Author

kpavlov commented Nov 6, 2025

set to draft to avoid conflicts with @devcrocod's changes

@kpavlov
Copy link
Contributor Author

kpavlov commented Nov 7, 2025

Use #376 instead

@kpavlov kpavlov closed this Nov 7, 2025
@kpavlov kpavlov deleted the kpavlov/refactor-errors-and-tests branch November 7, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation refactoring Making things better tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants